package com.xymtop.api.controller;

import com.xymtop.api.config.ServerStatus;
import com.xymtop.api.entity.IP;
import com.xymtop.api.service.IPService;
import com.xymtop.api.utils.JsonResoult;
import com.xymtop.api.utils.Timer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName : IPController
 * @Description : 版权管理控制器
 * @Author : 肖叶茂
 * @Date: 2022/12/1  18:52
 */
@RestController
@RequestMapping("ip")
public class IPController   {

    @Autowired
   private IPService ipService;

    @RequestMapping("add")
    public JsonResoult<String> add(@RequestParam("projectid") String projectid, @RequestParam("type") String type, @RequestParam("content") String content
    , @RequestParam("contenttype") String contenttype) {
        IP ip = new IP();
        ip.setId(Timer.getTimeStamp().toString());
        ip.setContenttype(contenttype);
        ip.setType(type);
        ip.setProjectid(projectid);
        ip.setContent(content);
        if(ipService.add(ip)==0){
            return new JsonResoult<>(ServerStatus.Fail);
        }else {
            return new JsonResoult<>(ServerStatus.SUCCESS);
        }
    }


    @RequestMapping("delete")
    public JsonResoult<String> delete(String id) {
        if(ipService.delete(id)==0){
            return new JsonResoult<>(ServerStatus.Fail);
        }else {
            return new JsonResoult<>(ServerStatus.SUCCESS);
        }
    }

@RequestMapping("getIP")
    public List<IP> getIP(String projectid) {
        return ipService.getIP(projectid);
    }
}
